/*
 * (C) Copyright 2016 Ymatou (http://www.ymatou.com/).
 * 
 * All rights reserved.
 */
package com.ymatou.iapi.userservice.parameter.enums;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
/**
 * 应用来源
 *
 * @author zhongwei
 */
/**
 * @author zhouyi
 *
 */
/**
 * @author zhouyi
 *
 */
public enum AppSourceEnum {

    /**
     * 码头主站
     */
    MainSite(0, "MainSite", "码头"),

    /**
     * 手机APP
     */
    App(1, "App", "码头APP"),

    /**
     * Wap
     */
    Wap(2, "Wap", "码头Wap"),

    /**
     * 阿里 - 废弃
     */
    Alipay(3, "Alipay", "支付宝"),

    /**
     * QQ - 废弃
     */
    QQ(4, "QQ", "QQ"),

    /**
     * 新浪微博 - 废弃
     */
    Weibo(5, "Weibo", "微博"),

    /**
     * 码头APP - 废弃
     * <p>
     * 聚洋货APP已下线
     */
    MatouApp(6, "MatouApp", "码头聚洋货APP"),

    /**
     * 商家后台
     */
    SellerSite(7, "SellerSite", "商家后台"),

    /**
     * 商家后台_APP
     */
    SellerApp(8, "SellerApp", "商家后台APP"),

    /**
     * 商家后台_Wap
     */
    SellerWap(9, "SellerWap", "商家后台Wap"),

    /**
     * 微信小程序
     */
    WxApp(20, "WxApp", "码头微信小程序"),

    /**
     * 头条抖音小程序
     */
    TouTiaoMiniApp(21, "TouTiaoMiniApp", "码头抖音小程序"),
    TouTiaoHuoShanApp(22, "TouTiaoHuoShanApp", "头条火山小程序"),	//	22
    /**
     * 直播App
     */
    AppLive(11, "AppLive", "码头直播APP"),
    /**
     * 苹果App--没了
     */
//    AppleApp(100, "AppleApp", "苹果APP"),
    /**
     * 未知来源
     */
    Other(100, "Other", "未知"),

    /**
     * 全球优选-推手App
     */
    GlobalApp(31, "GlobalApp", "码头优选APP"),

    /**
     * 全球优选-商城小程序
     */
    GlobalWxApp(32, "GlobalWxApp", "码头优选小程序"),

    /**
     * 全球优选-推手App-鱼多多
     */
    GlobalAppFish(33, "GlobalAppFish", "鱼多多优选APP"),

    /**
     * 全球优选-商城小程序-鱼多多
     */
    GlobalWxAppFish(34, "GlobalWxAppFish", "鱼多多优选小程序"),

    /**
     * 全球优选-微信公众号（H5）
     */
    GlobalWxWap(35, "GlobalWxWap", "码头优选Wap"),
    /**
     * 百度小程序
     */
    BaiduMiniApp(23, "BaiduMiniApp", "百度小程序"),
    /**
     * 支付宝小程序
     */
    AlipayMiniApp(36, "AlipayMiniApp", "支付宝小程序"),
    /**
     * 小海螺小程序
     */
    SmallConchMiniApp(25, "SmallConchMiniApp", "小海螺小程序"),
    /**
     * 全球优选公众号（推手专用）
     */
    GlobalHunterWap(39, "GlobalHunterWap", "码头优选Hunter");

    private Integer code;

    private String message;

    private String text;

    AppSourceEnum(Integer code, String message, String text) {
        this.code = code;
        this.message = message;
        this.text = text;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public String getText() {
        return text;
    }

    /**
     * 通过错误码获取枚举项
     *
     * @param code
     * @return
     */
    public static AppSourceEnum getByCode(Integer code) {
        for (AppSourceEnum appSourceEnum : AppSourceEnum.values()) {
            if (appSourceEnum.getCode() == code) {
                return appSourceEnum;
            }
        }
        return null;
    }

    public static AppSourceEnum getByMessage(String msg) {
        for (AppSourceEnum appSourceEnum : AppSourceEnum.values()) {
            if (appSourceEnum.getMessage().equalsIgnoreCase(msg)) {
                return appSourceEnum;
            }
        }
        return null;
    }

    public static AppSourceEnum getValue(String val) {
        if (StringUtils.isNumeric(val)) {
            return getByCode(NumberUtils.toInt(val));
        } else {
            return getByMessage(val);
        }
    }
}